import loaddata from "./loaddata_suggestion.js";
import navmain from "./nav_main.js";
import search from "./search.js";
import switchDisplay from "./switch_display.js";
import topicBanner from "./topic_banner.js";
import cart from "./cart.js";
import backToTop from "./back_to_top.js";
import haveLog from "./have_log.js";

export default function () {
    'use strict';
    $("#J_topbox_close").on("click", function () {
        // console.log();
        $(this).parent().remove();
    });

    $(".J_tnliHover").on("mouseenter", function () {
        $(this).addClass("hover");
    });
    $(".J_tnliHover").on("mouseleave", function () {
        $(this).removeClass("hover");
    });

    $(".cart-wrap").on("mouseenter", function () {
        $(this).addClass("mini-cart-over");
    });
    $(".cart-wrap").on("mouseleave", function () {
        $(this).removeClass("mini-cart-over");
    });
    //是否已登录
    haveLog();
    //假数据
    $.ajax({ url: "../data/products.json", dataType: "json" }).then(function (res) {
        window.data = res.data;
    });
    //搜索框业务
    loaddata().then(function (res) {
        search(res);
    });
    //主菜单显示隐藏业务
    navmain();
    //轮播图业务
    // Init Swiper  main-banner
    var swiper = new Swiper('.swiper-container', {
        slidesPerView: 1,
        autoplay: {
            delay: 4000,
            disableOnInteraction: false,
        },
        loop: true,
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        }
    });
    //切换显示商品业务
    switchDisplay();
    //话题轮播图业务
    topicBanner();
    //回到顶部业务
    backToTop();
    //获取购物车中商品数量
    var ls = localStorage.getItem("cart");
    if (ls !== "") {
        var ls_list = JSON.parse(ls);
        var good_count = 0;
        $.each(ls_list, function (index, item) {
            good_count += item.count;
        });
        $(".js-cart-num").html(good_count);
    }
    //购物车业务
    cart();
}